@extends('layouts.app', ['activePage' => 'competition', 'titlePage' => __('比赛管理')])
@section('content')
<div class="content">
  <div class="container-fluid">
      <div class="card">
          <div class="card-header card-header-primary">
            <h4 class="card-title">比赛列表</h4>
            <p class="card-category"> 比赛列表与管理 </p>
          </div>

          <div class="card-body ">
            @if (session('message'))
                <div class="row">
                  <div class="col-sm-12">
                    <div class="alert alert-success">
                      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <i class="material-icons">close</i>
                      </button>
                      <span>{{ session('message') }}</span>
                    </div>
                  </div>
                </div>
              @endif
              <div class="row justify-content-between">
                  <div class="col-md-auto mr-auto">
                    <ul class="nav">
                      <li class="nav-item">
                        <a class="nav-link active" href="?type">全部({{$all}})</a>
                      </li>
                      <li class="nav-item">
                          <a class="nav-link" href="?type=0">未发布({{$status0}})</a>
                      </li>
                      <li class="nav-item">
                          <a class="nav-link" href="?type=1">已发布({{$status1}})</a>
                      </li>
                      <li class="nav-item">
                          <a class="nav-link" href="?type=2">已下架({{$status2}})</a>
                      </li>
                    </ul>
                  </div>
                  <div class="col-auto">
                    <form class="navbar-form navbar-search" method="get">
                      <div class="input-group no-border">
                        <input type="text" name="search" class="form-control" placeholder="搜索比赛...">
                        <button type="submit" class="btn btn-white btn-round btn-just-icon">
                          <i class="material-icons">search</i>
                          <div class="ripple-container"></div>
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="col-auto">
                    <a href="{{ route('competitions.create') }}" class="btn btn-sm btn-primary"><i class="material-icons">add</i>新建</a>
                  </div>
                </div>
                <table class="table">
                  <thead>
                      <tr class="text-center text-primary">
                          <th>编号</th>
                          <th>图片</th>
                          <th>标题</th>
                          <th>介绍</th>
                          <th>截止时间</th>
                          <th>地点</th>
                          <th>报名列表</th>
                          <th>状态</th>
                          <th>操作</th>
                      </tr>
                  </thead>
                  @foreach ($competitions as $competition)
                  <tbody>
                      <tr class="text-center">
                          <td>{{ $loop->iteration }}</td>
                          <td style="max-width: 200px">
                            <img src="{{ $competition->image }}" class="rounded mx-auto d-block" width="50px" height="50px"
                            alt="Image of {{ $competition->title }}">
                          </td>
                          <td style="max-width: 200px">{{ $competition -> title}}</td>
                          <td class="text-truncate" style="max-width: 200px">{{ $competition->description}}</td>
                          <td>{{ $competition->deadline}}</td>
                          <td style="max-width: 200px">{{ $competition->location}}</td>
                          <td>
                              @if ($competition->status == 0)
                              <a href="#" class="alert-link text-muted">尚未发布</a>
                              @else
                              <a href="competitions/{{$competition->id}}/signup-list" class="alert-link">查看</a>
                              @endif
                          </td>
                          <td>
                              @switch($competition->status)
                              @case('0') <span class="badge badge-info">未发布</span> @break
                              @case('1') <span class="badge badge-success">已发布</span> @break
                              @case('2') <span class="badge badge-danger">已下架</span> @break
                              @endswitch
                          </td>
                          <td class="td-actions">

                              <button onclick="window.location.href = 'competitions/{{$competition->id}}/edit'" type="button" rel="tooltip"
                                  class="btn btn-success" {{ $competition->status!==1?'':'disabled' }}>
                                  <i class="material-icons">edit</i>
                              </button>
                              <div class="btn-group">
                                  <button type="submit" rel="tooltip" class="btn btn-danger dropdown-toggle"
                                      data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                      <i class="material-icons">build</i>
                                  </button>
                                  <div class="dropdown-menu">
                                      <form method="POST" action="/competitions/{{$competition->id}}">
                                          @method('delete')
                                          @csrf
                                          @if ($competition->status!==1)
                                          <button type="submit" class="dropdown-item w-75">发布比赛</button>
                                          @else
                                          <button type="submit" class="dropdown-item w-75">下架比赛</button>
                                          @endif
                                      </form>

                                  </div>
                              </div>
                          </td>
                      </tr>
                  </tbody>
                  @endforeach

              </table>

          </div>
  </div>
  </div>
</div>
@endsection

